package org.example.dao;

import org.apache.ibatis.annotations.*;
import org.example.pojo.User;

import java.util.List;

public interface UserDAO {
    @Select("select * from tb_user where id = #{id}")
    @Results(id = "userMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "orders", column = "id",
                    many = @Many(select = "org.example.dao.OrderDAO.findByUserId"))
    })
    public User findById(Integer id);

    @Select("select * from tb_user")
    public List<User> findAll();

    @Insert("insert into tb_user values(null,#{username},#{address})")
    public boolean save(User user);

    @Update("update tb_user set username=#{username},address=#{address} where id=#{id}")
    public boolean update(User user);

    @Delete("delete from tb_user where id=#{id}")
    public boolean delete(User  user);
}
